<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Validator Class Reference</title>
    <link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="../css/highlight.css" />
    <meta charset='utf-8'>
    <script src="../js/jquery.min.js" defer></script>
    <script src="../js/jazzy.js" defer></script>
    
  </head>
  <body>
    <a name="//apple_ref/swift/Class/Validator" class="dashAnchor"></a>
    <a title="Validator Class Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="../index.html">SwiftValidator Docs</a> (100% documented)</p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="../index.html">SwiftValidator Reference</a>
        <img id="carat" src="../img/carat.png" />
        Validator Class Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="../Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Classes/AlphaNumericRule.html">AlphaNumericRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/AlphaRule.html">AlphaRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/CharacterSetRule.html">CharacterSetRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/ConfirmationRule.html">ConfirmationRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/EmailRule.html">EmailRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/ExactLengthRule.html">ExactLengthRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/FloatRule.html">FloatRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/FullNameRule.html">FullNameRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/HexColorRule.html">HexColorRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/IPV4Rule.html">IPV4Rule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/ISBNRule.html">ISBNRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/MaxLengthRule.html">MaxLengthRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/MinLengthRule.html">MinLengthRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/PasswordRule.html">PasswordRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/PhoneNumberRule.html">PhoneNumberRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/RegexRule.html">RegexRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/RequiredRule.html">RequiredRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/ValidationError.html">ValidationError</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/ValidationRule.html">ValidationRule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/Validator.html">Validator</a>
              </li>
              <li class="nav-group-task">
                <a href="../Classes/ZipCodeRule.html">ZipCodeRule</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../Protocols/Rule.html">Rule</a>
              </li>
              <li class="nav-group-task">
                <a href="../Protocols/ValidationDelegate.html">ValidationDelegate</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            <h1>Validator</h1>
              <div class="declaration">
                <div class="language">
                  <pre class="highlight"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">Validator</span></code></pre>

                </div>
              </div>
            <p>Class that makes <code>Validator</code> objects. Should be added as a parameter to ViewController that will display
validation fields.</p>

          </section>
          <section class="section task-group-section">
            <div class="task-group">
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:vC14SwiftValidator9Validator11validationsGVSs10DictionaryCSo11UITextFieldCS_14ValidationRule_"></a>
                    <a name="//apple_ref/swift/Property/validations" class="dashAnchor"></a>
                    <a class="token" href="#/s:vC14SwiftValidator9Validator11validationsGVSs10DictionaryCSo11UITextFieldCS_14ValidationRule_">validations</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Dictionary to hold all fields (and accompanying rules) that will undergo validation.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">validations</span> <span class="o">=</span> <span class="p">[</span><span class="kt">UITextField</span><span class="p">:</span><span class="kt">ValidationRule</span><span class="p">]()</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:vC14SwiftValidator9Validator6errorsGVSs10DictionaryCSo11UITextFieldCS_15ValidationError_"></a>
                    <a name="//apple_ref/swift/Property/errors" class="dashAnchor"></a>
                    <a class="token" href="#/s:vC14SwiftValidator9Validator6errorsGVSs10DictionaryCSo11UITextFieldCS_15ValidationError_">errors</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Dictionary to hold fields (and accompanying errors) that were unsuccessfully validated.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="k">var</span> <span class="nv">errors</span> <span class="o">=</span> <span class="p">[</span><span class="kt">UITextField</span><span class="p">:</span><span class="kt">ValidationError</span><span class="p">]()</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC14SwiftValidator9ValidatorcFMS0_FT_S0_"></a>
                    <a name="//apple_ref/swift/Method/init()" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC14SwiftValidator9ValidatorcFMS0_FT_S0_">init()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">(){}</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>An initialized object, or nil if an object could not be created for some reason that would not result in an exception.</p>

                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/Public%20functions"></a>
                <a name="//apple_ref/swift/Section/Public functions" class="dashAnchor"></a>
                <a href="#/Public%20functions">
                  <h3 class="section-name">Public functions</h3>
                </a>
              </div>
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC14SwiftValidator9Validator13validateFieldFS0_FTCSo11UITextField8callbackFT5errorGSqCS_15ValidationError__T__T_"></a>
                    <a name="//apple_ref/swift/Method/validateField(_:callback:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC14SwiftValidator9Validator13validateFieldFS0_FTCSo11UITextField8callbackFT5errorGSqCS_15ValidationError__T__T_">validateField(_:callback:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>This method is used to validate a single field registered to Validator. If validation is unsuccessful,
field gets added to errors dictionary.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">validateField</span><span class="p">(</span><span class="nv">textField</span><span class="p">:</span> <span class="kt">UITextField</span><span class="p">,</span> <span class="nv">callback</span><span class="p">:</span> <span class="p">(</span><span class="nv">error</span><span class="p">:</span><span class="kt">ValidationError</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>textField</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Holds validator field data.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>No return value.</p>

                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/Using%20Keys"></a>
                <a name="//apple_ref/swift/Section/Using Keys" class="dashAnchor"></a>
                <a href="#/Using%20Keys">
                  <h3 class="section-name">Using Keys</h3>
                </a>
              </div>
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC14SwiftValidator9Validator17styleTransformersFS0_FT7successGSqFT14validationRuleCS_14ValidationRule_T__5errorGSqFT15validationErrorCS_15ValidationError_T___T_"></a>
                    <a name="//apple_ref/swift/Method/styleTransformers(success:error:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC14SwiftValidator9Validator17styleTransformersFS0_FT7successGSqFT14validationRuleCS_14ValidationRule_T__5errorGSqFT15validationErrorCS_15ValidationError_T___T_">styleTransformers(success:error:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>This method is used to style fields that have undergone validation checks. Success callback should be used to show common success styling and error callback should be used to show common error styling.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">styleTransformers</span><span class="p">(</span><span class="n">success</span> <span class="nv">success</span><span class="p">:((</span><span class="nv">validationRule</span><span class="p">:</span><span class="kt">ValidationRule</span><span class="p">)</span><span class="o">-&gt;</span><span class="kt">Void</span><span class="p">)?,</span> <span class="nv">error</span><span class="p">:((</span><span class="nv">validationError</span><span class="p">:</span><span class="kt">ValidationError</span><span class="p">)</span><span class="o">-&gt;</span><span class="kt">Void</span><span class="p">)?)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>success</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>A closure which is called with validationRule, an object that holds validation data</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>error</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>A closure which is called with validationError, an object that holds validation error data</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>No return value</p>

                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC14SwiftValidator9Validator13registerFieldFS0_FTCSo11UITextField5rulesGSaPS_4Rule___T_"></a>
                    <a name="//apple_ref/swift/Method/registerField(_:rules:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC14SwiftValidator9Validator13registerFieldFS0_FTCSo11UITextField5rulesGSaPS_4Rule___T_">registerField(_:rules:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>This method is used to add a field to validator.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">registerField</span><span class="p">(</span><span class="nv">textField</span><span class="p">:</span><span class="kt">UITextField</span><span class="p">,</span> <span class="nv">rules</span><span class="p">:[</span><span class="kt">Rule</span><span class="p">])</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>textField</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>field that is to be validated.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>Rule</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>An array which holds different rules to validate against textField.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>No return value</p>

                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC14SwiftValidator9Validator13registerFieldFS0_FTCSo11UITextField10errorLabelCSo7UILabel5rulesGSaPS_4Rule___T_"></a>
                    <a name="//apple_ref/swift/Method/registerField(_:errorLabel:rules:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC14SwiftValidator9Validator13registerFieldFS0_FTCSo11UITextField10errorLabelCSo7UILabel5rulesGSaPS_4Rule___T_">registerField(_:errorLabel:rules:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>This method is used to add a field to validator.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">registerField</span><span class="p">(</span><span class="nv">textField</span><span class="p">:</span><span class="kt">UITextField</span><span class="p">,</span> <span class="nv">errorLabel</span><span class="p">:</span><span class="kt">UILabel</span><span class="p">,</span> <span class="nv">rules</span><span class="p">:[</span><span class="kt">Rule</span><span class="p">])</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>textfield</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>field that is to be validated.</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>errorLabel</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>A UILabel that holds error label data</p>

                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>rules</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>A Rule array that holds different rules that apply to said textField.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>No return value</p>

                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC14SwiftValidator9Validator15unregisterFieldFS0_FCSo11UITextFieldT_"></a>
                    <a name="//apple_ref/swift/Method/unregisterField(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC14SwiftValidator9Validator15unregisterFieldFS0_FCSo11UITextFieldT_">unregisterField(_:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>This method is for removing a field validator.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">unregisterField</span><span class="p">(</span><span class="nv">textField</span><span class="p">:</span><span class="kt">UITextField</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>textField</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>field used to locate and remove textField from validator.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>No return value</p>

                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC14SwiftValidator9Validator8validateFS0_FPS_18ValidationDelegate_T_"></a>
                    <a name="//apple_ref/swift/Method/validate(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC14SwiftValidator9Validator8validateFS0_FPS_18ValidationDelegate_T_">validate(_:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>This method checks to see if all fields in validator are valid.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">validate</span><span class="p">(</span><span class="nv">delegate</span><span class="p">:</span><span class="kt">ValidationDelegate</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>No return value.</p>

                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FC14SwiftValidator9Validator8validateFS0_FFT6errorsGVSs10DictionaryCSo11UITextFieldCS_15ValidationError__T_T_"></a>
                    <a name="//apple_ref/swift/Method/validate(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FC14SwiftValidator9Validator8validateFS0_FFT6errorsGVSs10DictionaryCSo11UITextFieldCS_15ValidationError__T_T_">validate(_:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>This method validates all fields in validator and sets any errors to errors parameter of callback.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">validate</span><span class="p">(</span><span class="nv">callback</span><span class="p">:(</span><span class="nv">errors</span><span class="p">:[</span><span class="kt">UITextField</span><span class="p">:</span><span class="kt">ValidationError</span><span class="p">])</span><span class="o">-&gt;</span><span class="kt">Void</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Void</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>callback</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>A closure which is called with errors, a dictionary of type UITextField:ValidationError.</p>

                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>No return value.</p>

                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </section>
        </section>
        <section id="footer">
          <p>&copy; 2016 <a class="link" href="https://github.com/jpotts18/SwiftValidator" target="_blank" rel="external">Jeff Potter</a>. All rights reserved. (Last updated: 2016-04-15)</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.5.0</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
